home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-23 | 22.9 KB | 689 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UProgressIndicators.cp
- // ETO20 MacApp 3.3.1, MPW 3.4.1
- // Copyright ©1994-1996 Conrad Kopala
- // Twist Down Lists version 2.0a0 7/15/96
- //----------------------------------------------------------------------------------------
-
- #ifndef __UPROGRESSINDICATORS__
- #include "UProgressIndicators.h"
- #endif
-
- #ifndef __UTWISTDOWNGLOBALS__
- #include "UTwistDownGlobals.h"
- #endif
-
- //MacApp stuff
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- //ToolBox stuff
- //None
-
- //ANSI Stuff
- //None
-
-
- //----------------------------------------------------------------------------------------
- // Forward and external classes
- //----------------------------------------------------------------------------------------
- class TProgressBarBehavior; //forward
-
- //========================================================================================
- // Global Initialization Procedure
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUTwistDownView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- void InitUProgressDialog()
- {
-
- MA_REGISTER_CLASS(TProgressBarIndicator);
- MA_REGISTER_CLASS(TProgressDialogBehavior);
- MA_REGISTER_CLASS(TProgressWindow);
- MA_REGISTER_CLASS(TProgressView);
- MA_REGISTER_CLASS(TProgressBar);
-
- }
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // NewProgressBarIndicator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- TProgressBarIndicator* NewProgressBarIndicator(const CStr255& itsOperationString, const CStr255& itsSubjectString)
- {
- TProgressBarIndicator * theProgressBarIndicator;
-
- theProgressBarIndicator = new TProgressBarIndicator;
- theProgressBarIndicator -> IProgressBarIndicator(itsOperationString, itsSubjectString);
- return theProgressBarIndicator;
- }
- //========================================================================================
- // CLASS TProgressBarIndicator
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment ProgBarOpen
- MA_DEFINE_CLASS_M1(TProgressBarIndicator, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- TProgressBarIndicator::TProgressBarIndicator()
- {
- fMax = 0;
- fCurrent = 0;
- fStopped = TRUE;
- fProgressWindow = NULL;
- fProgressView = NULL;
- fSubjectString = "";
- fUpdateAmount = 1; //set to 1 so as a default the bar appears to be working.
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::~TProgressBarIndicator
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TProgressBarIndicator::~TProgressBarIndicator()
- {
- fProgressWindow = (TWindow*)FreeIfObject(fProgressWindow);
- fProgressView = NULL;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::IProgressBarIndicator
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- void TProgressBarIndicator::IProgressBarIndicator(const CStr255& operationString, const CStr255& subjectName)
- {
- this -> IObject();
- fOperationString = operationString;
- fSubjectString = subjectName;
- }
-
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::CreateProgressView
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- void TProgressBarIndicator::CreateProgressWindow()
- {
- MAVolatileInit(TWindow*, aProgressWindow, NULL);
- MAVolatileInit(TProgressView*, aProgressView, NULL);
- MAVolatileInit(TStaticText*, theStaticText, NULL);
- MAVolatileInit(TProgressDialogBehavior*, aProgressDialogBehavior, NULL);
-
- if (fProgressWindow == NULL)
- {
-
- if (qTemplateViews)
- {
-
- FailNIL(aProgressWindow = gViewServer -> NewTemplateWindow(kProgressWindowID, NULL));
- fProgressWindow = aProgressWindow;
- aProgressDialogBehavior = new TProgressDialogBehavior;
- aProgressDialogBehavior -> IProgressDialogBehavior(TRUE,'stop',' ');
- aProgressWindow -> AddBehavior(aProgressDialogBehavior);
- aProgressView = (TProgressView*) (aProgressWindow -> FindSubView(kProgressViewID));
- fProgressView = aProgressView;
- }
-
- theStaticText = (TStaticText*) (aProgressWindow -> FindSubView(kProgressOperationViewID));
- theStaticText -> SetText(fOperationString, kRedraw);
-
- theStaticText = (TStaticText*) (aProgressWindow -> FindSubView(kProgressSubjectViewID));
- theStaticText -> SetText(fSubjectString, kRedraw);
- theStaticText -> fHelpID = kProgressDialogHelp;
- theStaticText -> fHelpIndex = 1;
- fProgressView -> PrepareToStart(TRUE);
-
- }
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::Continue
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBarIndicator::Continue()
- {
- if (this -> WasCancelled())
- {
- this -> Stop();
- }
- else if (!this -> IsStopped())
- {
- fCurrent = fCurrent + fUpdateAmount;
- this -> DoContinue(fUpdateAmount);
- }
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::DoUpdate
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBarIndicator::DoUpdate(ChangeID theChange,
- TObject* changedObject, TObject* changedBy,TDependencySpace* dependencySpace)
- {
- if (theChange == mUpdateProgressBar)
- this -> Continue();
- else
- Inherited::DoUpdate(theChange, changedObject, changedBy, dependencySpace);
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::PrepareToStart
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- void TProgressBarIndicator::PrepareToStart(Boolean redraw)
- {
- MAVolatileInit(Boolean, hasWindow, TRUE);
-
- if (fProgressWindow == NULL)
- hasWindow = FALSE;
-
- if (hasWindow == FALSE)
- this -> CreateProgressWindow();
-
- FlushEvents(everyEvent, 0);
- this -> DrawAtOnce(redraw);
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::Reset
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBarIndicator::Reset()
- {
- fMax = 0;
- fCurrent = 0;
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::Start
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBarIndicator::Start(long max)
- {
- fMax = max;
- fCurrent = 0;
- fStopped = FALSE;
- fProgressView -> Start(max);
- fStopped = FALSE;
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::Stop
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBarIndicator::Stop()
- {
- fStopped = TRUE;
- fProgressWindow -> Close();
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::IsStopped
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- Boolean TProgressBarIndicator::IsStopped()
- {
- return fStopped;
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::DoContinue
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBarIndicator::DoContinue(long howMuch)
- {
- fProgressView -> Continue(howMuch);
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::DrawAtOnce
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBarIndicator::DrawAtOnce(Boolean wholeThing)
- {
- if (fProgressWindow == NULL)
- this -> PrepareToStart(kRedraw);
- else
- {
- if (!fProgressWindow -> IsShown())
- {
- fProgressWindow -> Select();
- fProgressWindow -> Open();
- }
-
- if (wholeThing)
- fProgressWindow -> ForceRedraw();
-
- if (fProgressWindow -> Focus())
- fProgressWindow -> Update();
- } //end else
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::WasCancelled
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- Boolean TProgressBarIndicator::WasCancelled()
- {
- MAVolatileInit(Boolean, result, FALSE);
- MAVolatileInit(TProgressDialogBehavior*, itsProgressDialogBehavior, NULL);
-
- itsProgressDialogBehavior = (TProgressDialogBehavior*)(fProgressWindow -> GetBehaviorWithIdentifier(kDialogBehavior));
-
- if (itsProgressDialogBehavior)
- {
- FailInfo fi;
- Try(fi)
- {
- result = itsProgressDialogBehavior -> WasCancelled();
- fi.Success();
- }
- else // Recover
- {
- fProgressWindow -> CloseAndFree();
- fi.ReSignal();
- }
- }
- else
- {
- fProgressWindow -> CloseAndFree();
- #if qDebug
- ProgramBreak("Can’t test WasCancelled because the window doesn’t contain a TProgressDialogBehavior.");
- #endif
-
- gErrorParm3 = "TProgressDialogBehavior"; // show name of class
- Failure(errMissingClass, 0);
- }
-
- return result;
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::GetBarLength
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- long TProgressBarIndicator::GetBarLength()
- {
- return fProgressView -> GetBarLength();
- }
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator::SetUpdateAmountTo
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBarIndicator::SetUpdateAmountTo(long updateAmount)
- {
- fUpdateAmount = updateAmount;
- }
- //========================================================================================
- // CLASS TProgressDialogBehavior
- //========================================================================================
- #undef Inherited
- #define Inherited TDialogBehavior
-
- #pragma segment ProgBarOpen
- MA_DEFINE_CLASS_M1(TProgressDialogBehavior, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TProgressDialogBehavior constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- TProgressDialogBehavior::TProgressDialogBehavior()
- {
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TProgressDialogBehavior::~TProgressDialogBehavior
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- TProgressDialogBehavior::~TProgressDialogBehavior()
- {
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TProgressDialogBehavior::IProgressDialogBehavior
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- void TProgressDialogBehavior::IProgressDialogBehavior(Boolean isModal,IDType itsDefaultItem,IDType itsCancelItem)
- {
- this -> IDialogBehavior(isModal,itsDefaultItem,itsCancelItem);
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressDialogBehavior::WasCancelled
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- Boolean TProgressDialogBehavior::WasCancelled()
- {
- fDismissed = FALSE;
- fDismisser = kNoIdentifier;
- MAVolatile(short, oldEventMask);
- oldEventMask = gApplication->GetMainEventMask();
- gApplication -> SetMainEventMask(oldEventMask & ~highLevelEventMask);
-
- FailInfo fi;
- Try(fi)
- {
- //Note: I've never forced a failure here to see what happens.
- if (!fDismissed)
- gApplication->PollEvent(kAllowApplicationToSleep);
-
- gApplication->SetMainEventMask(oldEventMask);
- fi.Success();
- }
- else
- {
- gApplication->SetMainEventMask(oldEventMask);
- fi.ReSignal();
- }
-
- return fDismissed;
- }
- //========================================================================================
- // CLASS TProgressWindow
- //========================================================================================
- #undef Inherited
- #define Inherited TWindow
-
- #pragma segment ProgBarOpen
- MA_DEFINE_CLASS_M1(TProgressWindow, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TProgressWindow constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- TProgressWindow::TProgressWindow()
- {
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TProgressWindow::~TProgressWindow
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- TProgressWindow::~TProgressWindow()
- {
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TProgressWindow::IProgressWindow
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- void TProgressWindow::IProgressWindow(TDocument* itsDocument,WindowPtr itsWMgrWindow,
- Boolean canResize,Boolean canClose,Boolean disposeOnFree)
- {
- this -> IProgressWindow(itsDocument,itsWMgrWindow,canResize,canClose,disposeOnFree);
- }
- //========================================================================================
- // CLASS TProgressView
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment ProgBarOpen
- MA_DEFINE_CLASS_M1(TProgressView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TProgressView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- TProgressView::TProgressView()
- {
- fProgressBar = NULL;
- fStopButton = NULL;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressView::~ TProgressView
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
- TProgressView::~TProgressView()
- {
- fProgressBar = NULL;
- fStopButton = NULL;
-
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressView::IProgressView
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- void TProgressView::IProgressView(TDocument* itsDocument,TView* itsSuperView,
- const VPoint& itsLocation,const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,SizeDeterminer itsVSizeDet)
- {
- this -> IView(itsDocument,itsSuperView,itsLocation,itsSize,itsHSizeDet,itsVSizeDet);
- }
- //----------------------------------------------------------------------------------------
- // TProgressView::Continue
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressView::Continue(long howMuch)
- {
- fProgressBar -> Continue(howMuch);
- }
- //----------------------------------------------------------------------------------------
- // TProgressView::DrawAtOnce
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressView::DrawAtOnce(Boolean redraw)
- {
- #pragma unused redraw
- }
- //----------------------------------------------------------------------------------------
- // TProgressView::PrepareToStart
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressView::PrepareToStart(Boolean redraw)
- {
- #pragma unused redraw
- fProgressBar = (TProgressBar*) (this -> FindSubView(kProgressBarViewID));
- fProgressBar -> SetBarSize();
- fProgressBar -> SetPen();
- fProgressBar ->fHelpID = kProgressDialogHelp;
- fProgressBar ->fHelpIndex = 2;
- }
- //----------------------------------------------------------------------------------------
- // TProgressView::Reset
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressView::Reset()
- {
- fProgressBar -> Reset();
- }
- //----------------------------------------------------------------------------------------
- // TProgressView::Start
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressView::Start(long max)
- {
- fProgressBar -> Start(max);
- }
- //----------------------------------------------------------------------------------------
- // TProgressView::Stop
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressView::Stop()
- {
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressView::GetBarLength
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- long TProgressView::GetBarLength()
- {
- return fProgressBar -> GetBarLength();
- }
- //========================================================================================
- // CLASS TProgressBar
- //========================================================================================
- #undef Inherited
- #define Inherited TControl
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M1(TProgressBar, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TProgressBar constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- TProgressBar::TProgressBar()
- {
- fMax = 0;
- fCurrent = 0;
- fBarRect = gZeroVRect;
-
- #if qDebug
- this -> PrintAppConstructorClassInfo();
- #endif
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::~TProgressBar
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TProgressBar::~TProgressBar()
- {
- #if qDebug
- this -> PrintAppDestructorClassInfo();
- #endif
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::IProgressBar
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- void TProgressBar::IProgressBar(TView* itsSuperView,const VPoint& itsLocation,const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,SizeDeterminer itsVSizeDet,const TextStyle& itsTextStyle)
- {
- this -> IControl(itsSuperView,itsLocation,itsSize,itsHSizeDet,itsVSizeDet,itsTextStyle);
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::SetBarSize
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- void TProgressBar::SetBarSize()
- {
- fBarRect.right = fSize.h;
- fBarRect.bottom = fSize.v;
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::SetPen
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarOpen
- void TProgressBar::SetPen()
- {
- GetPenState(&fPen);
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::Draw
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBar::Draw(const VRect& area)
- {
- #pragma unused area
- PenState oldPen;
- PenState newPen;
- VRect barRect;
- long barLength;
- VRect controlArea;
- CRect qdArea;
-
- if (fCurrent > 0)
- {
-
- GetPenState(&oldPen);
- newPen = fPen;
- SetPenState(&newPen);
- barRect = fBarRect;
- barLength = barRect.right - barRect.left;
- barRect.right = ((barLength*fCurrent)/fMax);
-
- if (barRect.right > fBarRect.right)
- barRect.right = fBarRect.right;
-
- this -> ViewToQDRect(barRect, qdArea);
- PaintRect(qdArea);
-
- SetPenState(&oldPen);
- }
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::Continue
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBar::Continue(long howMuch)
- {
- fCurrent = fCurrent + howMuch;
- VRect area;
-
- this -> DrawContents();
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::Reset
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBar::Reset()
- {
- fCurrent = 0;
- this -> Update();
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::Start
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBar::Start(long max)
- {
- fMax = max;
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::Stop
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- void TProgressBar::Stop()
- {
-
- }
- //----------------------------------------------------------------------------------------
- // TProgressBar::GetBarLength
- //----------------------------------------------------------------------------------------
- #pragma segment ProgBarRes
- long TProgressBar::GetBarLength()
- {
- return fSize.h;
- }
-
- #pragma segment Inline